package com.lancoo.klgcourseware.ui.fragment.operate;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.lancoo.klgcourseware.R;
import com.lancoo.klgcourseware.entity.bean.SpellCharacterBean;
import com.lancoo.klgcourseware.ui.adapter.PronunciatioPhraseAdapter;
import com.lancoo.klgcourseware.utils.KlgToolUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by pengmi on 2019/8/28 17:11
 * Description:
 */
public class AlertRPronunceESPTrainOperateFragment extends AlertBaseFragment {


    private List<SpellCharacterBean> spellCharacterBeanList;
    private boolean haiSlowTrain=true;
    private PronunciatioPhraseAdapter mAdapter;
    private RecyclerView recyclerView;

    @Override
    protected int getContentViewId() {
        return R.layout.klg_fragment_alert_phonetic_train;
    }

    @Override
    protected void initView(View view) {
        String klgName=getArguments().getString("klgName");
        recyclerView = view.findViewById(R.id.alert_recycler_view);
        spliteData(klgName);
        view.findViewById(R.id.tv_i_know).setOnClickListener(this);

//        TextView tv_phonetic = view.findViewById(R.id.tv_phonetic);
//        tv_phonetic.setText(UniCodeUtils.convertToChinese(phonetic));
        RelativeLayout rl_reading=view.findViewById(R.id.rl_spell_content_alert);
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) rl_reading.getLayoutParams();
//        int margTop= KlgToolUtils.dip2px(getContext(),KlgToolUtils.isPad(getContext())?246:202);
        int topMargin=KlgToolUtils.dip2px(getContext(),KlgToolUtils.isPad(getContext())?210:192);
        layoutParams.topMargin=topMargin+KlgToolUtils.getStatusHeight(getContext());
        ImageView img_alertLogo = view.findViewById(R.id.img_alert_logo);
        img_alertLogo.setImageResource(R.mipmap.klg_icon_alert_esp_pronounce);
//        try{
//            Typeface typeFace = Typeface.createFromAsset(getContext().getAssets(), "klg_droid_sans_bold.ttf");
//            tv_phonetic.setTypeface(typeFace);
//        }catch (Exception e){
//
//        }
    }

    /**
     * 分割数据
     */
    private void spliteData(String klgName){
        spellCharacterBeanList=new ArrayList<>();
        if(TextUtils.isEmpty(klgName)){
            return;
        }
        String[] split = klgName.split(" ");
        for (int i = 0; i < split.length; i++) {
            SpellCharacterBean spellCharacterBean=new SpellCharacterBean();
            spellCharacterBean.setCharacter(split[i]);
            spellCharacterBeanList.add(spellCharacterBean);
        }
        mAdapter=new PronunciatioPhraseAdapter(getContext(),spellCharacterBeanList,klgName);
        mAdapter.setAlert(true);
        mAdapter.setTrainModel(true,false);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext(),LinearLayoutManager.HORIZONTAL,false));
        recyclerView.setAdapter(mAdapter);

    }

    @Override
    public void onClick(View v) {
        if(System.currentTimeMillis()-time<500){
            return;
        }
        time=System.currentTimeMillis();
        super.onClick(v);
        int id=v.getId();
        if(id==R.id.tv_i_know){
            closeAlertOperate();
        }
    }
}
